<!doctype html>
<html>
<head>
	<meta charset="utf-8">
	<title>悬赏房源</title>
	<meta name="keywords" content="">
	<meta name="description" content="">
	<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <link rel="stylesheet" type="text/css" href="css/reset.css">
    <script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
    <script src="js/sha1.js"></script>
	<style>
        .richScan{
            margin: .4rem auto;
            text-align: center;
        }
	</style>
</head>
<body>
	<div id="layout">
        <div class="richScan">
            <input id="btn" type="button" value="扫一扫">
        </div>
    </div>
</body>
<script type="text/javascript" src="plugins/jquery.min.js"></script>
<script type="text/javascript" src="js/common.js"></script>
<script type="text/javascript">
    function initWXConfig() {
        this.nonceStr = "";
        this.timestamp = "";
        this.appId = "";
        this.token=common.getToken();
        this.currentUrl=window.location.href;
        this.url=common.globalHost+common.getSignture;
        this.debug = false;
        // 所有要调用的 API 都要加到这个列表中
        this.jsApiList = [
            'scanQRCode'
        ];
        this.signature = '';
        this.getJSApi_ticket();
    }
    initWXConfig.prototype = {
        getJSApi_ticket: function() {
            var self = this;
            common.requestFormData({
                url:self.url,
                sendData:{fullPath:self.currentUrl,token:self.token},
                resSuccess:function(data){
                    console.log(data);
                     var data=data.res.data;
                    self.timestamp=data.timestamp;
                    self.appId=data.appId;
                    self.nonceStr=data.nonceStr;
                    self.signature=data.signature;
                    self.setConfig();

                },
                resFailed:function(){

                }
            });
        },
        setConfig: function() {
            var self = this;
            wx.config({
                debug: self.debug,
                appId: self.appId,
                timestamp: self.timestamp,
                nonceStr: self.nonceStr,
                signature: self.signature,
                jsApiList: self.jsApiList
            });
        },
        scanQRCode:function(){
            wx.scanQRCode({
                needResult: 1, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果，
                scanType: ["qrCode","barCode"], // 可以指定扫二维码还是一维码，默认二者都有
                success: function (res) {
                    var result = res.resultStr; // 当needResult 为 1 时，扫码返回的结果
                    // console.log(result);
                    window.location.href=result;
                }
            });
        }
    }
    window.wxinit = new initWXConfig();
    wx.ready(function() {
        var $btn=$('#btn');
        $btn.off('touchend').on('touchend',function(e){
            wxinit.scanQRCode();
        }) 
    });
    wx.error(function (res) {//错误时调用
        alert(res.errMsg);
    });

</script>
</html>